﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GIMS.MODEL;

namespace KPIS.GERP.GIMS.DAL
{
    public sealed class SysControlDAL
    {
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

        public SysControlDAL()
        {

        }

        public SysControlInfo GetDefaultData()
        {
            string strSQL;
            DataSet ds = null;
            DataRowCollection dr = null;
            SysControlInfo info = new SysControlInfo();
            try
            {
                dbManager.Open();

                strSQL = "SELECT * FROM ICM_SYS_CONTROL WHERE YEAR_TYPE_SEQ = 1";

                ds = dbManager.ExecuteDataSet(CommandType.Text, strSQL);
                dr = ds.Tables[0].Rows;
                if (dr.Count > 0)
                {
                    info.YearType = (Convert.IsDBNull(dr[0]["YEAR_TYPE_SEQ"]) ? null : (Nullable<int>)(dr[0]["YEAR_TYPE_SEQ"]));
                    info.Year = (Convert.IsDBNull(dr[0]["BGM_YEAR"]) ? null : (Nullable<int>)(dr[0]["BGM_YEAR"]));
                    info.VatPercent = (Convert.IsDBNull(dr[0]["DEFAULT_VAT_PERCENT"]) ? null : (Nullable<double>)(dr[0]["DEFAULT_VAT_PERCENT"]));
                    info.InvJobSite = (Convert.IsDBNull(dr[0]["INV_JOB_SITE_SEQ"]) ? null : (Nullable<int>)(dr[0]["INV_JOB_SITE_SEQ"]));
                    info.DepJobSite = (Convert.IsDBNull(dr[0]["DEP_JOB_SITE_SEQ"]) ? null : (Nullable<int>)(dr[0]["DEP_JOB_SITE_SEQ"]));
                }
                return info;
            }
            catch
            {
                return info;
            }
            finally
            {
                dbManager.Dispose();
            }
        }
    }
}
